/*
 * ModifyCost.cpp
 *
 *  Created on: 2013-2-3
 *      Author: Administrator
 */

#include "ModifyCost.h"

ModifyCost::ModifyCost(QWidget * parent):QDialog(parent), typeLabel(tr("类型名称")),
commentLabel(tr("类型说明")), modifyButton(tr("添加")), cancleButton(tr("取消")), mode(addMode), id(0)
{
	qDebug() << "enter ModifyCost::ModifyCost";
	checkBox.setText("是否启用");
	layout.addWidget(&typeLabel, 0, 0);
	layout.addWidget(&nameLineEdit, 0, 1);
	layout.addWidget(&checkBox, 0, 2);
	layout.addWidget(&commentLabel, 1, 0);
	layout.addWidget(&textEdit, 1, 1, 2, 2);
	layout.addWidget(&modifyButton, 5, 0);
	layout.addWidget(&cancleButton, 5, 2);
	this->setLayout(&layout);
	setWindowTitle("修改支出类型");
	connect(&modifyButton, SIGNAL(clicked()), this, SLOT(slt_addOrModify()));
	connect(&cancleButton, SIGNAL(clicked()), this, SLOT(close()));
	qDebug() << "exit ModifyCost::ModifyCost";
}

void ModifyCost::setMode(const int &mode, const int &id,
		const QString &name, const QString &comment, bool active)
{
	this->mode = mode;
	this->id = id;

	if(mode == modifyMode)
	{
		setWindowTitle("修改支出类型");
		modifyButton.setText("确认修改");
		checkBox.setChecked(active);
	}
	else
	{
		modifyButton.setText("确认添加");
		checkBox.setChecked(true);
		setWindowTitle("添加支出类型");
	}
	nameLineEdit.setText(name);
	textEdit.setPlainText(comment);
}
void ModifyCost::slt_addOrModify()
{
	emit sig_modifyOrAdd(mode, id, nameLineEdit.text(), textEdit.toPlainText(), checkBox.isChecked());
//	emit sig_addOrModify(mode, id, nameLineEdit.text(), nameLineEdit.text(), checkBox.checkState());
	qDebug() << "enter ModifyCost::slt_addOrModify() and emit sig_addOrModify";
	this->close();
}
ModifyCost::~ModifyCost() {
	// TODO Auto-generated destructor stub
}

